#include "widget.h"
#include "ui_widget.h"
#include <QRect>

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    // forget设置图标
    ui->pushButton_forget->setIcon(QIcon(":/image/LuFei.jpg"));
    ui->pushButton_forget->setIconSize(QSize(90, 90));
    // 设置上下左右
    ui->pushButton_up->setIcon(QIcon(":/image/up.png"));
    ui->pushButton_up->setIconSize(QSize(110, 110));
    ui->pushButton_down->setIcon(QIcon(":/image/down.png"));
    ui->pushButton_down->setIconSize(QSize(110, 110));
    ui->pushButton_left->setIcon(QIcon(":/image/left.png"));
    ui->pushButton_left->setIconSize(QSize(110, 110));
    ui->pushButton_right->setIcon(QIcon(":/image/right.png"));
    ui->pushButton_right->setIconSize(QSize(110, 110));
    // 设置快捷键
    ui->pushButton_up->setShortcut(QKeySequence("w")); // 大小写都可以触发
//    ui->pushButton_up->setShortcut(QKeySequence("W"));
    ui->pushButton_down->setShortcut(QKeySequence("s")); // 大小写都可以触发
    ui->pushButton_left->setShortcut(QKeySequence("a")); // 大小写都可以触发
    ui->pushButton_right->setShortcut(QKeySequence("d")); // 大小写都可以触发
}

Widget::~Widget()
{
    delete ui;
}


void Widget::on_pushButton_up_clicked()
{
    QRect rect = ui->pushButton_forget->geometry();
    ui->pushButton_forget->setGeometry(rect.x(), rect.y() - 10, rect.width(), rect.height());
}

void Widget::on_pushButton_down_clicked()
{
    QRect rect = ui->pushButton_forget->geometry();
    ui->pushButton_forget->setGeometry(rect.x(), rect.y() + 10, rect.width(), rect.height());
}

void Widget::on_pushButton_left_clicked()
{
    QRect rect = ui->pushButton_forget->geometry();
    ui->pushButton_forget->setGeometry(rect.x() - 10, rect.y(), rect.width(), rect.height());
}

void Widget::on_pushButton_right_clicked()
{
    QRect rect = ui->pushButton_forget->geometry();
    ui->pushButton_forget->setGeometry(rect.x() + 10, rect.y(), rect.width(), rect.height());
}
